package com.chinasoft.ssm.service.impl;

public class AccountServiceImpl2 {
    /*
     @Override
    public int transfer(String from, String to, int money) {

        // 获取事务的定义
        DefaultTransactionDefinition tf = new DefaultTransactionDefinition();
        // 开启事务
        TransactionStatus status = tx.getTransaction(tf);

        int flag = 0;

        try {
            // 查询 from
            Account fromAcc = accountMapper.selectByName(from);
            if (fromAcc == null) {
                flag = 1;
                // 手工抛异常
                throw new RuntimeException("from account not founded");
            }
            // 查询 to
            Account toAcc = accountMapper.selectByName(to);
            if (toAcc == null) {
                flag = 2;
                throw new RuntimeException("to account not founded");
            }
            // 修改 from 的钱
            fromAcc.setMoney(fromAcc.getMoney() - money);
            if (fromAcc.getMoney() < 0) {
                flag = 3;
                throw new RuntimeException("money is not enough !");
            }
            accountMapper.updateMoeny(fromAcc);
            // 修改 to 的钱
            toAcc.setMoney(toAcc.getMoney() + money);
            accountMapper.updateMoeny(toAcc);

            System.out.println("数据提交到数据库 。。。");
            // 进行数据提交
            tx.commit(status);
            return 0;
        } catch (Exception e) {
            // 进行事务的回滚
            tx.rollback(status);
            System.out.println("数据 rollback 。。。");
            return flag;
        }
    }
    *
     */

}
